package pl.edu.agh.iosr.gamblingzone.action;

import java.util.List;

import javax.ejb.EnterpriseBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

import pl.edu.agh.iosr.gamblingzone.dao.DisciplineDAO;
import pl.edu.agh.iosr.gamblingzone.dao.ParticipantDAO;
import pl.edu.agh.iosr.gamblingzone.dao.ejb.DisciplineDAOBean;
import pl.edu.agh.iosr.gamblingzone.dao.ejb.ParticipantDAOBean;
import pl.edu.agh.iosr.gamblingzone.model.Discipline;
import pl.edu.agh.iosr.gamblingzone.model.Participant;

@Stateless
@Name("disciplinesManage")
public class DisciplinesManageAction implements DisciplinesManage {

	@PersistenceContext
	EntityManager entityManager;

	private DisciplineDAO disciplineDAO;

	private List<Discipline> allDisciplines;

	private void setupDAO() {
		if (disciplineDAO == null) {
			disciplineDAO = new DisciplineDAOBean();
			((DisciplineDAOBean) disciplineDAO).setEntityManager(entityManager);
		}
	}

	public void addDiscipline(Discipline d) {
		// TODO Auto-generated method stub

	}

	public List<Discipline> getAllDisciplines() {
		setupDAO();
		allDisciplines = disciplineDAO.findAll();
		return allDisciplines;
	}

	public void removeDiscipline(Discipline d) {
		setupDAO();
		disciplineDAO.makeTransient(d);

	}
}
